<?php 	

class AttributeController extends AuthController{

   private $model;

  public function __init(){
       
     // 为了不覆盖父类authcontroller里面的init方法
    	parent::__init();
    	$this->model=K('Attribute');
 }

// 显示首页列表
 public function index(){
$type_id=Q('get.type_id',0,'intval');
 $this->assign('type_id',$type_id);
  $data= $this->model->where("type_id='$type_id'")->all();
 
  $this->assign('data',$data);
  // p($data);die;
    $this->display();


 }
 
// 添加属性
 public function add(){
   $type_id=Q('get.type_id',0,'intval');

     

 	if(IS_POST){
 
     

  if(!$this->model->addData()){
  	$this->error($this->model->error);
  }
    $this->success('添加成功',U('Attribute/index',array('type_id'=>$type_id)));

 	}
    $this->display();
 }

// 修改属性
 public function edit(){
   $type_id=Q('get.type_id',0,'intval');
    if(IS_POST){
     $attr_id=Q('post.attr_id',0,'intval');
       if(!$this->model->edit($attr_id)){
        $this->error($this->model->error);
       }
       $this->success('修改成功',U('Attribute/index',array('type_id'=>$type_id)));

    }
    // 获取旧数据
    $attr_id=Q('get.attr_id',0,'intval');
   $olddata=$this->model->where("attr_id={$attr_id}")->find();
   $this->assign('olddata',$olddata);

    $this->display();

 }


// 删除

 public function del(){
 $attr_id=Q('get.attr_id',0,'intval');
 $this->model->where("attr_id={$attr_id}")->delete();
 $this->success('删除成功');

 }













}




















 ?>